<?php

use think\migration\Migrator;
use think\migration\db\Column;

class JSBundleRecord extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('js_bundle_record');
        $table
            ->addColumn('app_version', 'string', ['limit' => 50, 'null' => false, 'comment' => 'App version'])
            ->addColumn('app_buildnumber', 'string', ['limit' => 20, 'null' => true, 'comment' => 'App build number'])
            ->addColumn('js_version', 'string', ['limit' => 50, 'null' => false, 'comment' => 'JS bundle version'])
            ->addColumn('platform', 'integer', ['null' => false, 'comment' => 'Platform: 1 ios/2 安卓'])
            ->addColumn('md5', 'string', ['limit' => 64, 'null' => false, 'comment' => 'MD5 hash'])
            ->addColumn('enabled', 'boolean', ['default' => 1, 'comment' => 'Is enabled'])
            ->addColumn('zip_url', 'string', ['limit' => 255, 'null' => false, 'comment' => 'Zip package download URL'])
            ->addColumn('created_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP', 'comment' => 'Created time'])
            ->addColumn('updated_at', 'datetime', ['null' => true, 'comment' => 'Updated time'])
            ->addColumn('bundle_id', 'string', ['limit' => 50, 'null' => false, 'comment' => 'App bundle id'])
            ->addIndex(['app_version', 'app_buildnumber', 'js_version'])
            ->create();
    }
}
